/* Copyright (c) 2007-2024 by Kithara Software GmbH. All rights reserved. */

//##############################################################################################################
//
// File:         NetworkUdpReceive.h
//
// Used Modules: Network Module
//
// Description:  Shared definitions between user space application and kernel space DLL for example of
//               simple implementation of a UDP receiver
//
// Creator:      r.gro 2007-12-11
//
//##############################################################################################################

   /*=====================================================================*\
   |                    *** DISCLAIMER OF WARRANTY ***                     |
   |                                                                       |
   |       THIS  CODE AND INFORMATION IS PROVIDED "AS IS"  WITHOUT         |
   |       A  WARRANTY OF  ANY KIND, EITHER  EXPRESSED OR  IMPLIED,        |
   |       INCLUDING  BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF         |
   |       MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.        |
   \*=====================================================================*/

   //##############################################################################################################
   //
   // Purpose:
   //
   // This example shows how to receive UDP datagrams.
   //
   // First we open the network adapter and create a socket.
   // A receive callback is installed at kernel level, to put incoming data into a message pipe and set an event.
   // A receive thread of the application, waiting for that event, gets the data from the pipe and displays it.
   //
   // This sample is designed to be the counterpart to the sample NetworkUdpSend.
   //
   // PLEASE SPECIFY YOUR IP-ADDRESS, SUBNET-MASK AND GATEWAY-IP-ADDRESS IN THE KS_makeIPv4() CALLS AS WELL AS
   // THE PORT TO USE IN THE APPLICATION PROGRAM BEFORE RUNNING THIS EXAMPLE!
   //
   //##############################################################################################################

#ifndef __SMP_NETWORKUDPRECEIVE_H
#define __SMP_NETWORKUDPRECEIVE_H

#include "../_KitharaSmp/_KitharaSmp.h"


//--------------------------------------------------------------------------------------------------------------
// This is the size limit for the receive buffers, used by the receiving thread of the application, as well
// as by the socket receive function in the kernel DLL
//--------------------------------------------------------------------------------------------------------------

const int bufferSize = 2048;


//--------------------------------------------------------------------------------------------------------------
// SharedData is a user defined argument structure for information exchange using shared memory between the
// kernel space DLL and the user space application.
// You are free to define your own system bitsize independent arguments in any class.
//--------------------------------------------------------------------------------------------------------------

struct SharedData {
    KSHandle hKernel;                                     // Handle of the kernel
    KSHandle hAdapter;                                    // Handle of the network adapter
    KSHandle hPipe;                                       // Handle of the data pipe
    KSHandle hReceiveEvent;                               // Handle of the signaling event
    KSHandle hSocketCallBack;                             // Handle of the callback to be installed on the socket
    KSHandle hSocket;                                     // Handle of the socket
    KSIPConfig ipConfig;                                  // Address information for the socket
    uint listeningPort;                                   // Port to listen on
    uint serverIp;                                        // IP Address of the target to connect to

    char pSendBuffer[256];                                // Buffer containing the text to send through the socket
    int sendLength;                                       // Length of the text within the buffer

    char pDeviceName[256];                                // Name of the network adapter
    uint isFinished;                                      // Flag indicating the state of the socket communication
};

#endif // __SMP_NETWORKUDPRECEIVE_H